/**
 * @Author: Lenovo
 * @Date: 2024/6/8 10:43
 * @description:
 */
public class MyInteger {
    private int value;
    private static MyInteger[]cache=new MyInteger[256];
    public static final int LOW=-128;
    public static final int HIGH=127;
    private MyInteger(int i){
        this.value=i;
    }
    //静态代码块先被执行
    static {
        for(int i=MyInteger.LOW;i<=HIGH;i++){
            cache[i+128]=new MyInteger(i);
        }
    }
    public int intValue(){
        return this.value;
    }
    public static MyInteger ValueOf(int i){
        if(i>=LOW&&i<=HIGH){
            return cache[i+128];
        }
        return new MyInteger(i);
    }

    @Override
    public String toString() {
        return this.value+"";
    }

    public static void main(String[] args) {
        MyInteger i=MyInteger.ValueOf(10);
        MyInteger a=MyInteger.ValueOf(1000);
        System.out.println(i);
        System.out.println(a);
    }
}
